import Vue from 'vue';
import Router from 'vue-router';

Vue.use(Router);

const router = new Router({
    mode: 'history',
    routes: [{
        path: "/",
        redirect: "/home/",
    },
        {
            path: "/home/",
            component: () =>
                import ('../view/Home.vue'),
            children: [{
                path: '/',
                component: () =>
                    import ('../view/Home/Default')
            },
                {
                    path: 'QuestionBase',
                    component: () =>
                        import ('../view/Home/QuestionBase.vue'),
                },
                {
                    path: 'QuestionBaseDetail',
                    component: () =>
                        import ('../view/Home/QuestionBaseDetail.vue')
                },
                {
                    path: 'Paper',
                    component: () =>
                        import ('../view/Home/Paper.vue')
                },
                {
                    path: 'PaperDetail',
                    component: () =>
                        import ('../view/Home/PaperDetail.vue')
                },
                {
                    path: 'PaperAddQuestion',
                    component: () =>
                        import ('../view/Home/PaperAddQuestion.vue')
                },
                {
                    path: 'Organization',
                    component: () =>
                        import ('../view/Home/Organization.vue')
                },
                {
                    path: 'Examination',
                    component: () =>
                        import ('../view/Home/Examination.vue'),
                },
                {
                    path: 'MineExamination',
                    component: () =>
                        import ('../view/Home/MineExamination.vue')
                }
            ]
        },
        {
            path: "/answer",
            name:"answer",
            component: () =>
                import('../view/Home/components/Examination/Answer')
        },
        {
            name: "Login",
            path: "/login",
            component: () =>
                import ('../view/Login.vue')
        },
        // {
        //     path:'/test',
        //     component:()=>import('@/view/Home/Test')
        // },
        {
            path: '*',
            component: () =>
                import ('@/components/404')
        }
    ]
})

//路由守卫
router.beforeEach((to, from, next) => {
    let user = router.app.$store.getters.getuser;
    if (to.name !== 'Login' && !user) {
        next({name: "Login"})
    } else next();

})

export default router